package cn.jasonone.jame.model;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import lombok.Data;

/**
 * 尺寸类
 *
 * @author Jason
 */
@Data
public class Dimension {
    /**
     * 宽度
     */
    private DoubleProperty width = new SimpleDoubleProperty(0);
    /**
     * 高度
     */
    private DoubleProperty height = new SimpleDoubleProperty(0);

    public Dimension(){
        this(0,0);
    }

    public Dimension(double width,double height){
        this.setDimension(width,height);
    }

    /**
     * 将当前尺寸变更为指定尺寸
     *
     * @param dimension 尺寸对象
     */
    public void setDimension(Dimension dimension) {
        this.setDimension(dimension.getWidth(), dimension.getHeight());
    }

    /**
     * 将当前尺寸变更为指定尺寸
     *
     * @param width  宽度
     * @param height 高度
     */
    public void setDimension(double width, double height) {
        setWidth(width);
        setHeight(height);
    }

    /**
     * 绑定尺寸
     *
     * @param dimension 尺寸对象
     */
    public void bindDimension(Dimension dimension) {
        this.widthProperty().bindBidirectional(dimension.widthProperty());
        this.heightProperty().bindBidirectional(dimension.heightProperty());
    }

    /**
     * 解绑尺寸
     *
     * @param dimension 尺寸对象
     */
    public void unbindDimension(Dimension dimension) {
        this.widthProperty().unbindBidirectional(dimension.widthProperty());
        this.heightProperty().unbindBidirectional(dimension.heightProperty());
    }

    public double getWidth() {
        return width.get();
    }

    public DoubleProperty widthProperty() {
        return width;
    }

    public void setWidth(double width) {
        this.width.set(width);
    }

    public double getHeight() {
        return height.get();
    }

    public DoubleProperty heightProperty() {
        return height;
    }

    public void setHeight(double height) {
        this.height.set(height);
    }
}
